import numpy as np

points=np.array([[1,1],[2,3],[3,2],[4,3]])
# 提取2列数据
x=points[:,0]
y=points[:,1]
# 定义损失函数
def compute_cost(w,b,points):
    total_cost=0
    M=len(points)
    for i in range(M):
        x=points[i,0]
        y=points[i,1]
        total_cost+=(y-w*x-b)**2
    return total_cost/M
# 训练模型
from sklearn.linear_model import LinearRegression
lr=LinearRegression()
x_new=x.reshape(-1,1)
y_new=y.reshape(-1,1)
lr.fit(x_new,y_new)
w=lr.coef_
b=lr.intercept_
print(w,b)
